//
//  BaseTableViewController.swift
//  SinaWeibo
//
//  Created by Arvin on 15/11/8.
//  Copyright © 2015年 Arvin. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController, VisitorLoginViewDelegate { // 遵守协议 -> 继承协议
    //MARK: 外部的属性
    var visitorLoginView: VisitorLoginView?
    // 用户已授权且access_token有效 则加载系统tableView
    var userLogin = UserAccountViewModel().userLogin
    override func loadView() {
        userLogin ? super.loadView() : loadVisitorLoginView() // 这里加载的是函数
    }
    
    //MARK: 按钮点击
    func userWillLogin() {
        let OAuth = OAuthViewController()
        let nav = UINavigationController(rootViewController: OAuth)
        presentViewController(nav, animated: true, completion: nil)
    }
    
    func userWillRegister() {
        print("register")
    }

    private func loadVisitorLoginView() {
        visitorLoginView = VisitorLoginView()
        // 设置代理
        visitorLoginView?.visitorDelegat = self
        view = visitorLoginView
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Done, target: self, action: "userWillLogin")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Done, target: self, action: "userWillRegister")
//        navigationController?.navigationBar.tintColor = UIColor.orangeColor()
    }
}
